﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace G.Net.Oauth
{
    [DataContract]
    public class OAuthRequestToken
    {
        [DataMember]
        public string Token { get; set; }

        [DataMember]
        public string Secret { get; set; }
    }

    [DataContract]
    public class OAuthAccessToken : OAuthRequestToken
    {

        [DataMember]
        public string UserID { get; set; }

        public static void Save(string name, OAuthAccessToken token)
        {
            string str = string.Format("{0} {1} {2}", token.Token, token.Secret, token.UserID);
            Windows.Storage.ApplicationData.Current.LocalSettings.Values[name] = str;
        }

        public static OAuthAccessToken Load(string name)
        {

            if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(name))
            {
                string str = Windows.Storage.ApplicationData.Current.LocalSettings.Values[name] as string;
                if (!string.IsNullOrEmpty(str))
                {
                    string[] array = str.Split(' ');
                    if (array.Length == 3)
                    {
                        OAuthAccessToken token = new OAuthAccessToken();
                        token.Token = array[0];
                        token.Secret = array[1];
                        token.UserID = array[2];
                        return token;
                    }
                    else
                        return null;
                }
                else
                    return null;
            }
            else
                return null;


        }
    }
}
